<template>
  <el-container>
    <!--    <el-aside>-->
    <el-aside width="200px">
      <Asidemenu></Asidemenu>
    </el-aside>
    <el-container>
      <el-header>
        <Strong>music后台管理系统</Strong>
        <div class="right-layout">
<!--          https://cube.elemecdn.com/0/88/03b0d39583f48206768a7534e55bcpng.png-->
          <el-avatar :src="userInfo.avatar"></el-avatar>

          <a>{{ userInfo.username }}</a>
          <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>刷新信息</el-dropdown-item>
              <el-dropdown-item>修改密码</el-dropdown-item>
              <el-dropdown-item @click.native="loginOut">退出</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </el-header>
      <el-main>
        <div style="margin: 2px;">
          <Tabmenu></Tabmenu>
          <div style="margin: 0 15px;">
            <router-view/>
          </div>
        </div>
      </el-main>
    </el-container>
  </el-container>
</template>

<script>
import Asidemenu from './asidemenu'
import Tabmenu from './tabmenu'
import {mapState} from 'vuex'

export default {
  components: {
    Asidemenu,
    Tabmenu
  },
  data: function () {
    return {
      userInfo: {},
      activeIndex: '2'
    }
  },
  methods: {
    handleSelect(key, keyPath) {
      console.log(key, keyPath);
    },
    loginOut: function () {
      console.log("退出登录");
      //跳转到login页面
      window.localStorage.removeItem("userInfo");//移除会话存储中的用户信息。
      window.sessionStorage.removeItem("store");
      window.localStorage.removeItem("access_token");
      this.$store.commit("resetState");
      this.$router.replace({path: "/login"})
    },
    // 获取用户信息
    getUserInfo() {
      this.$axios.get("/sys/userInfo").then(res => {
        console.log("收到用户头像信息：" + JSON.stringify(res.data.data));
        this.userInfo = res.data.data
      })
    },

  },
  created() {
    this.getUserInfo();
  },

  mounted: function () {
    // let userInfo = JSON.parse(localStorage.getItem("userInfo")); // 获取用户信息
    // this.userInfo = userInfo;
    this.userInfo = {
      username: "admin"
    }
  },
  computed: {}
}
</script>

<style>
.el-container {
  padding: 0;
  margin: 0;
  height: 100%;
}

.header-avatar {
  float: right;
  width: 210px;
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.el-dropdown-link {
  cursor: pointer;
}

.el-header {
  background-color: #17B3A3;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #D3DCE6;
  color: #333;
  line-height: 200px;
}

.el-main {
  color: #333;
  padding: 0;
}

a {
  text-decoration: none;
  margin: 0 10px 0 10px;
}

.right-layout {
  float: right;
  display: flex;
  justify-content: space-around;
  align-items: center;
}
</style>
